{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Python27\\lib\\site-packages\\pandas\\_libs\\__init__.py:4: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected zd, got zd\n",
      "  from .tslib import iNaT, NaT, Timestamp, Timedelta, OutOfBoundsDatetime\n",
      "C:\\Python27\\lib\\site-packages\\pandas\\__init__.py:26: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected zd, got zd\n",
      "  from pandas._libs import (hashtable as _hashtable,\n",
      "C:\\Python27\\lib\\site-packages\\pandas\\core\\dtypes\\common.py:6: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected zd, got zd\n",
      "  from pandas._libs import algos, lib\n",
      "C:\\Python27\\lib\\site-packages\\pandas\\core\\util\\hashing.py:7: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected zd, got zd\n",
      "  from pandas._libs import hashing, tslib\n",
      "C:\\Python27\\lib\\site-packages\\pandas\\core\\indexes\\base.py:7: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected zd, got zd\n",
      "  from pandas._libs import (lib, index as libindex, tslib as libts,\n",
      "C:\\Python27\\lib\\site-packages\\pandas\\tseries\\offsets.py:21: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected zd, got zd\n",
      "  import pandas._libs.tslibs.offsets as liboffsets\n",
      "C:\\Python27\\lib\\site-packages\\pandas\\core\\ops.py:16: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected zd, got zd\n",
      "  from pandas._libs import algos as libalgos, ops as libops\n",
      "C:\\Python27\\lib\\site-packages\\pandas\\core\\indexes\\interval.py:32: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected zd, got zd\n",
      "  from pandas._libs.interval import (\n",
      "C:\\Python27\\lib\\site-packages\\pandas\\core\\internals.py:14: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected zd, got zd\n",
      "  from pandas._libs import internals as libinternals\n",
      "C:\\Python27\\lib\\site-packages\\pandas\\core\\sparse\\array.py:33: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected zd, got zd\n",
      "  import pandas._libs.sparse as splib\n",
      "C:\\Python27\\lib\\site-packages\\pandas\\core\\window.py:36: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected zd, got zd\n",
      "  import pandas._libs.window as _window\n",
      "C:\\Python27\\lib\\site-packages\\pandas\\core\\groupby\\groupby.py:68: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected zd, got zd\n",
      "  from pandas._libs import (lib, reduction,\n",
      "C:\\Python27\\lib\\site-packages\\pandas\\core\\reshape\\reshape.py:30: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected zd, got zd\n",
      "  from pandas._libs import algos as _algos, reshape as _reshape\n",
      "C:\\Python27\\lib\\site-packages\\pandas\\io\\parsers.py:45: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected zd, got zd\n",
      "  import pandas._libs.parsers as parsers\n",
      "C:\\Python27\\lib\\site-packages\\pandas\\io\\pytables.py:50: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected zd, got zd\n",
      "  from pandas._libs import algos, lib, writers as libwriters\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import sys\n",
    "sys.path.append(r'C:\\Users\\user\\OneDrive\\myGit\\qidian\\base-data-import')\n",
    "from import_config import *\n",
    "from utils.DatabaseUtil import *\n",
    "from services.OrganizationImport import start_town_village_import\n",
    "import traceback\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "reload(sys)\n",
    "sys.setdefaultencoding('utf-8')\n",
    "assert sys.getdefaultencoding().lower() == \"utf-8\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# encoding: utf-8\n",
    "\n",
    "import json\n",
    "import os\n",
    "import pandas as pd\n",
    "from import_config import *\n",
    "from utils.DatabaseUtil import execute_insert, IS_IN_MEMORY_TEST\n",
    "from utils.StringUtil import remove_str_symbol\n",
    "from utils.TownVillageCodeUtil import extract_town_village_name\n",
    "\n",
    "\n",
    "# ####################################################\n",
    "# 街道、社区基础信息导入，预设 乌鲁木齐市，新市区\n",
    "\n",
    "def start_vehicle_import():\n",
    "\n",
    "    file_count=0\n",
    "    for file_name in os.listdir(community_file_path):\n",
    "        if not file_name.__contains__(\".xlsx\") and not file_name.__contains__(\".xls\"):\n",
    "            continue\n",
    "        #try:\n",
    "\n",
    "        file_count += 1\n",
    "        print \"开始处理第 \".encode(\"utf-8\") + file_count.__str__() \\\n",
    "              + \" 个文件: \".encode(\"utf-8\") + file_name.decode(SYS_CHARSET).encode(\"utf-8\")\n",
    "\n",
    "        vehicle_execl_data = vehicle_execl_reader(file_name, sheet_name=0,\n",
    "                                                      skiprows=3 , names=VEHICLE_DATA_FILE_COLS,\n",
    "                                                      usecols=\"A:M\")\n",
    "        for i in vehicle_execl_data.man_name:\n",
    "            if i!=\"nan\":\n",
    "                print(i)\n",
    "        #print(vehicle_execl_data.man_name)\n",
    "\n",
    "        # except Exception as ex:\n",
    "        #     print(\"+++++++++++++++++++ 问题文件: \" + file_name.decode(SYS_CHARSET).encode(\"utf-8\"))\n",
    "\n",
    "\n",
    "            # move_excel_to_failed(file_name)\n",
    "\n",
    "\n",
    "\n",
    "VEHICLE_DATA_FILE_COLS = [\"man_name\", \"idcard\",\n",
    "                            \"cell_phone_num\", \"phone_num\", \"expiration_date_of_live\", \"man_type\", \"is_mark_person\",\n",
    "                            \"registered_man_totol\", \"can_into\", \"apartment_num\",\n",
    "                            \"unit_num\", \"room_num\", \"registered_by_who\"]\n",
    "community_file_path = os.path.join(DATA_FILE_PATH, 'vehicle')\n",
    "\n",
    "\n",
    "def vehicle_execl_reader(file_name, sheet_name=None, skiprows=0, names=None, usecols=None):\n",
    "    return pd.read_excel(os.path.join(community_file_path, file_name),\n",
    "                         sheet_name=sheet_name, skiprows=skiprows,\n",
    "                         names=names, usecols=usecols)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "ename": "IOError",
     "evalue": "[Errno 0] Error",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mIOError\u001b[0m                                   Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-8-bc8510b3585a>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m     24\u001b[0m         \u001b[0;31m#start_dept_import()\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     25\u001b[0m        \u001b[0;31m# start_community_import()\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 26\u001b[0;31m         \u001b[0mstart_vehicle_import\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     27\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     28\u001b[0m         \u001b[0;32mprint\u001b[0m \u001b[0;34m\"end\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mC:\\Users\\user\\OneDrive\\myGit\\qidian\\base-data-import\\services\\vehicle.pyc\u001b[0m in \u001b[0;36mstart_vehicle_import\u001b[0;34m()\u001b[0m\n\u001b[1;32m     23\u001b[0m         \u001b[0mfile_count\u001b[0m \u001b[0;34m+=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     24\u001b[0m         \u001b[0;32mprint\u001b[0m \u001b[0;34m\"开始处理第 \"\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mencode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"utf-8\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mfile_count\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__str__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;31m \u001b[0m\u001b[0;31m\\\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 25\u001b[0;31m               \u001b[0;34m+\u001b[0m \u001b[0;34m\" 个文件: \"\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mencode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"utf-8\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mfile_name\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdecode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mSYS_CHARSET\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mencode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"utf-8\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     26\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     27\u001b[0m         vehicle_execl_data = vehicle_execl_reader(file_name, sheet_name=0,\n",
      "\u001b[0;31mIOError\u001b[0m: [Errno 0] Error"
     ]
    }
   ],
   "source": [
    "# encoding: utf-8\n",
    "\n",
    "import traceback\n",
    "\n",
    "from import_config import *\n",
    "from utils.DatabaseUtil import *\n",
    "from services.DeptImport import start_dept_import\n",
    "from services.OrganizationImport import start_town_village_import\n",
    "from services.CommunityImport import start_community_import\n",
    "from services.vehicle import start_vehicle_import\n",
    "reload(sys)\n",
    "sys.setdefaultencoding('utf-8')\n",
    "assert sys.getdefaultencoding().lower() == \"utf-8\"\n",
    "\n",
    "# ####################################################\n",
    "# main 入口\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "\n",
    "        init_db()\n",
    "        #town_village_codes = start_town_village_import()\n",
    "        #start_town_village_import()\n",
    "        #start_dept_import()\n",
    "       # start_community_import()\n",
    "        start_vehicle_import()\n",
    "\n",
    "        print \"end\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
